<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator" style="text-align:right;">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <!-- <a-button type="primary" icon="download" @click="handleExportXls('形审分组表')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload> -->
      <!-- 高级查询区域 -->
      <!-- <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown> -->
    </div>

    <!-- table区域-begin -->
    <div>
      <!-- <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div> -->

    <!-- :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}" -->
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
        <!-- 分配成果 -->
        <span slot="resultsAction" slot-scope="text, record">
            <a style="width: 16px; margin-right: 5px;">
                <img @click="handleResult(record)" style="width:14px;height:14px;cursor:pointer;" src="../../assets/img/xuanze.png" alt="">
            </a>
            <span style="width: 40px;display: inline-block;">{{ record.xmsl }}{{ record.xmsl ? '个' : '' }}</span>
        </span>
        <!-- 分配专家 -->
        <span slot="expertAction" slot-scope="text, record">
            <a style="width: 16px; margin-right: 5px;">
                <img @click="handleExpert(record)" style="width:14px;height:14px;cursor:pointer;" src="../../assets/img/xuanze.png" alt="">
            </a>
            <span style="min-width: 40px;display: inline-block;">{{ record.zjlist }}</span>
        </span>
        <span slot="action" slot-scope="text, record">
            <a @click="handleEdit(record)">编辑</a>
            <a-divider type="vertical" />
            <a @click="deleteGroup(record.id)">删除</a>
        </span>
      </a-table>
    </div>
    <!-- 新增|修改分组 -->
    <cxj-xssc-fz-modal ref="modalForm" @ok="modalFormOk"></cxj-xssc-fz-modal>
    <!-- 分配成果 -->
    <cxj-xssc-fp-cg-form ref="fpCgForm" :resultFlag="resultFlag" :flId="flId" :groupId="groupId" @addResult="addResult"></cxj-xssc-fp-cg-form>
    <!-- 分配专家 -->
    <cxj-xssc-fp-zj-form ref="fpZjForm" :expertFlag="expertFlag" :groupId="groupId" @addExpert="addExpert"></cxj-xssc-fp-zj-form> 
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import CxjXsscFzModal from './modules/CxjXsscFzModal'
  import CxjXsscFpCgForm from './modules/CxjXsscFpCgForm.vue';
  import CxjXsscFpZjForm from "./modules/CxjXsscFpZjForm"
  import {
    cxjxsFzxmadd,
    cxjxsFzzjadd
  } from "@/api/api"
  import {
      postAction
  } from "@/api/manage"
  export default {
    name: 'CxjXsscFzList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
        CxjXsscFzModal,
        CxjXsscFpCgForm,
        CxjXsscFpZjForm
    },
    data () {
        return {
            description: '形审分组表管理页面',
            // 表头
            columns: [
                {
                    title: "序号",
                    dataIndex: '',
                    key:'rowIndex',
                    width:60,
                    align:"center",
                    customRender:function (t,r,index) {
                        return parseInt(index)+1;
                    },
                    // fixed: "left",
                },
                {
                    title:  '分组序号',
                    align: "center",
                    dataIndex: 'xssc_fz_xh'
                },
                {
                    title: '分组名称',
                    align: "center",
                    dataIndex: 'xssc_fz_mc'
                },
                {
                    title: '已分配成果',
                    align: "center",
                    dataIndex: 'xmsl',
                    scopedSlots: { customRender: 'resultsAction' }
                },
                {
                    title: '分组专家',
                    align: "center",
                    dataIndex: 'xsscFzzj',
                    scopedSlots: { customRender: 'expertAction' }
                },
                {
                    title: '操作',
                    align: "center",
                    fixed: "right",
                    width: 147,
                    dataIndex: 'action',
                    scopedSlots: { customRender: 'action' }
                }
            ],
            url: {
                list: "/cxj/cxjXsscFz/cxjxs_fzList",
                delete: "/cxj/cxjXsscFz/delete",
                deleteBatch: "/cxj/cxjXsscFz/deleteBatch",
                exportXlsUrl: "/cxj/cxjXsscFz/exportXls",
                importExcelUrl: "cxj/cxjXsscFz/importExcel",
            },
            dictOptions:{},
            superFieldList:[],
            resultFlag: false,
            expertFlag: false,
            groupId: "",
            flId: ''
        }
    },
    created() {
        this.$set(this.dictOptions, 'isValid', [{text:'是',value:'Y'},{text:'否',value:'N'}])
        this.getSuperFieldList();
    },
    computed: {
        importExcelUrl: function(){
            return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
        },
    },
    methods: {
        // 添加成果
        addResult(data){
            if (data.ids) {
                let formData = new FormData();
                formData.append('ids', data.ids);
                formData.append('xsfzid', data.xsfzid)
                cxjxsFzxmadd(formData).then(res=>{
                    if (res.success) {
                        this.$message.success(res.message);
                        this.$refs.fpCgForm.selectedResultlist();
                        this.$refs.fpCgForm.waitResultList();
                        this.$refs.fpCgForm.selectedRowKeys = [];
                        // this.resultFlag = !this.resultFlag;
                        this.loadData();
                    } else {
                        this.$message.success(res.message);
                    }
                })
            } else {
                this.$message.warning("请选择要添加的成果");
            }   
        },
        addExpert(data){
            if (data.ids) {
                let formData = new FormData();
                formData.append('ids', data.ids);
                formData.append('xsfzid', data.xsfzid)
                cxjxsFzzjadd(formData).then(res=>{
                    if (res.success) {
                        this.$message.success(res.message);
                        this.$refs.fpZjForm.waitExpertList();
                        this.$refs.fpZjForm.selectedExpertList();
                        this.$refs.fpZjForm.expertIds = [];
                        this.loadData();
                    } else {
                        this.$message.success(res.message);
                    }
                })
            } else {
                this.$message.warning("请选择要添加的专家！");
            }
            
        },
        // 分配成果
        handleResult(record){
            this.resultFlag = !this.resultFlag;
            this.groupId = record.id;
            this.flId = record.flId;
            console.log('231231231',record)
        },
        // 分配专家
        handleExpert(record){
            console.log('分配专家')
            this.expertFlag = !this.expertFlag;
            this.groupId = record.id;
        },
        // 删除分组
        deleteGroup(id){
            let that = this;
            this.$confirm({
                title: '确定要删除吗?',
                // content: 'Some descriptions',
                okText: '确定',
                // okType: 'danger',
                cancelText: '取消',
                onOk() {
                    let formData = new FormData();
                    formData.append('id', id)
                    postAction(that.url.delete, formData).then((res)=>{
                        if(res.success){
                            that.$message.success(res.message);
                            that.$emit('ok');
                            that.loadData();
                        }else{
                            that.$message.warning(res.message);
                        }
                    }).finally(() => {
                        that.confirmLoading = false;
                    })
                },
                onCancel() {
                    console.log('Cancel');
                },
            });
        },
        destroyAll() {
            this.$destroyAll();
        },
        initDictConfig(){},
        getSuperFieldList(){
            let fieldList=[];
            fieldList.push({type:'string',value:'flId',text:'分类编号',dictCode:''})
            fieldList.push({type:'int',value:'xsscFzXh',text:'分组序号',dictCode:''})
            fieldList.push({type:'string',value:'xsscFzBh',text:'分组编号',dictCode:''})
            fieldList.push({type:'string',value:'xsscFzMc',text:'分组名称',dictCode:''})
            fieldList.push({type:'string',value:'shijian',text:'年度',dictCode:''})
            fieldList.push({type:'switch',value:'isValid',text:'是否有效'})
            fieldList.push({type:'string',value:'bz1',text:'备注1',dictCode:''})
            fieldList.push({type:'string',value:'bz2',text:'备注2',dictCode:''})
            this.superFieldList = fieldList
        }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>